package com.kedacom.freedomLabel.model.bean;

import android.arch.persistence.room.Entity;
import android.arch.persistence.room.PrimaryKey;
import android.support.annotation.NonNull;
import android.text.TextUtils;

import com.kedacom.freedomLabel.excel.IRowRecord;
import com.kedacom.freedomLabel.model.db.Converters;
import com.kedacom.freedomLabel.utils.Cn2Spell;

/**
 * Author：李程
 * CreateTime：2020/6/5 00:36
 * E-mail：licheng@kedacom.com
 * Describe：操作员
 */
@Entity
public class Operator extends IFirstLetter implements IMainSelectItem , IRowRecord {

    // 索引 数据导出时 应忽略
    @NonNull
    @PrimaryKey
    public String uuid = Converters.randomUUID();

    // 用户姓名
    public String name;

    // 用户卡号
    public String cardNumber;

    public String extraData1;
    public String extraData2;
    public String extraData3;

    // 备注
    public String remark;

    // 缩写（拼音首字母）
    public String shortHand;

    // 创建时间
    public Long createTime;

    // 更新时间
    public Long updateTime;


    @Override
    public String getFirstLetter() {
        if (TextUtils.isEmpty(this.name)) {
            return "#";
        }
        String firstLetter = Cn2Spell.getPinYin(this.name).substring(0, 1).toUpperCase();
        if (!firstLetter.matches("[A-Z]")) {
            return "#";
        }
        return firstLetter;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) return true;
        if (obj == null) return false;
        if (obj instanceof Item) {
            Item other = (Item) obj;
            return TextUtils.equals(this.uuid, other.uuid);
        }
        return false;
    }

    @Override
    public String getItemName() {
        return this.name;
    }

    @Override
    public String[] getSelectResultData() {
        return new String[]{this.cardNumber, this.name};
    }

    @NonNull
    @Override
    public String[] rowValues() {
        return new String[]{cardNumber,name,extraData1,extraData2,extraData3,remark};
    }

    @Override
    public boolean[] isNumber() {
        return new boolean[0];
    }
}